import {request} from "@/utils/api";
import type {AxiosResponse} from "axios";

export interface Video {
  recordAt: string
  videoId: string
  name: string
  src: string
  previewImg: string
  videoTags: VideoTag[]
  durationTags: DurationTag[]
}

export interface VideoTag {
  id: number
  content: string
}

export interface DurationTag {
  id: number
  second: number
  content: string
}

export interface Pager {
    page: number
    size: number
    total?: number
}

export interface ReqGetVideoList extends Pager {
    keywords?: string
}

export interface RespGetVideoList extends Pager {
    data: Video[]
}

export const getVideoList = (req?: ReqGetVideoList) :Promise<AxiosResponse<Base<RespGetVideoList>>> => {
    return request.get('/video/list', {
        params: req
    });
}

export interface ReqGetVideoByRandom {
    keywords?: string
}

export const getVideoByRandom = (req: ReqGetVideoByRandom) :Promise<AxiosResponse<Base<Video>>> => {
    return request.get('/video/get/random', {
        params: req
    });
}

export interface ReqDeleteVideo {
    videoId: string
    password: string
}

export const deleteVideo = (req: ReqDeleteVideo) :Promise<AxiosResponse<Base<null>>> => {
    return request.delete(`/video/${req.videoId}`, {
        data: {
            password: req.password,
        },
    })
}

export interface ReqAddVideoTagForVideo {
    videoId: string
    name: string
}

export interface RespAddVideoTagForVideo {
    id: number
}

export const addVideoTagForVideo = (req: ReqAddVideoTagForVideo) :Promise<AxiosResponse<Base<RespAddVideoTagForVideo>>> => {
    return request.post(`/video/${req.videoId}/videoTag/add`, {
        name: req.name,
    })
}

export interface ReqDeleteVideoTag {
    id: number
}

export const deleteVideoTag = (req: ReqDeleteVideoTag) :Promise<AxiosResponse<Base<null>>> => {
    return request.delete(`/videoTag/${req.id}`)
}

export interface ReqAddDurationTagForVideo {
    videoId: string
    starSecond: number
    content: string
}

export interface RespAddDurationTagForVideo {
    id: number
}

export const addDurationTagForVideo = (req: ReqAddDurationTagForVideo) :Promise<AxiosResponse<Base<RespAddDurationTagForVideo>>> => {
    return request.post(`/video/${req.videoId}/durationTag/add`, {
        starSecond: req.starSecond,
        comment: req.content,
    })
}

export interface ReqDeleteDurationTag {
    id: number
}

export const deleteDurationTag = (req: ReqDeleteDurationTag) :Promise<AxiosResponse<Base<null>>> => {
    return request.delete(`/durationTag/${req.id}`)
}

